// model-loader.js
import * as THREE from "three";
import { FBXLoader } from "three/addons/loaders/FBXLoader.js";

// 添加一个进度回调函数
export function loadModel(url, onProgress) {
  const loader = new FBXLoader();

  return new Promise((resolve, reject) => {
    loader.load(
      url,
      (model) => {
        resolve(model); // 模型加载完成
      },
      (xhr) => {
        if (onProgress) {
          const progress = (xhr.loaded / xhr.total) * 100;
          onProgress(progress); // 更新进度
        }
      },
      (error) => {
        reject(error); // 错误处理
      }
    );
  });
}
